﻿<?php
//print_r($_GET);//Array ( [pid] => 158 )
extract($_GET);
include_once("../function.php");
$sql="select * from ts_product where pid=$_GET[pid]";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)==1)
	{
		$one=mysqli_fetch_assoc($res);
	}
	
}
$a=explode(",",$one['pimgs']);
?>
<!doctype html>
<html>
 <head>
  <title>商品详情页</title>
  <meta charset="utf-8"/>
 <link rel="stylesheet" href="./xqy.css">
 <style>a{text-decoration:none;}</style>
 </head>

 <body>
	<div id="big">
		<div id="top">
			<div class="tb">
				<span style=" margin-left:15px;"><a href="./index.php">网站首页</a>&nbsp;|&nbsp;用户中心&nbsp;
				<?php if(isset($_COOKIE["username"])){?>
				<span class="sy"><a href="shopcar.php">我的购物车(0)</a></span>
				<span class="sy"><a href="user_order.php">我的订单(0))</a></span><span class="ty">
				<?php }?>
				<?php if(!isset($_COOKIE["username"])){ ?>
					<a href="./login.php" style="float:right;">|&nbsp;登录</a>
					<a href="./regist.php" style="float:right;margin-right:25px;">免费注册</a>
					<?php }else{?>
					<font size=3 color="#ababab">您好！<?=$_COOKIE["username"]?>，<b>欢迎来到欣才商城！</b>|
					<a href="./out2.php">退出</a></font>
					<?php }?>
					</span>
			</div>

			<div>
				<font style="margin-left:20px" size=6>欣才&nbsp;&nbsp;</font><font color="1F81B0" size=6>商城</font>
				
				<input type="text" size="30px"/>
				<input type="submit" name="sub" value="搜索"/>
			</div>
			<div class="bj">
				<ul>
					<li><a href="./index.php">首页</a></li>
					<li>|</li>
					<li><a href="./index.php">商城</a></li>
					<li>|</li>
					<li><a href="./news.php?cid=32">新闻</a></li>
					<li>|</li>
					<li><a href="">活动</a></li>
					<li>|</li>
					<li><a href="">论坛</a></li>
				</ul>
			</div>
			<div id="s">
				<span class="sp"><font color="#a2a2a2">当前所在:</font>商城>中级课程>c239</span>
			</div>
			<hr color="#e2e2e2"/>
		</div>
		<div id="middle">
			<div id="left"><img src="../<?=$one['thumb']?>" width="450px" height="500px" id="one"/></div>

			<div id="xt1">
			<?php if(!empty($one['pimgs'])){for($i=0;$i<count($a);$i++){?>
				<div class="xt"><img src="../<?=$a[$i]?>" onclick="change(this)" width="90px" height="80px"></div>
			<?php }}?>
			</div>

			<div id="right">
			<form action="do_add_cart.php" method="get" name="form">
				<table width="600px" height="600px" border=0 cellspacing=0 >
				
					<tr>
						<td colspan=2 style="font-size:1.2em;"><?=$one['pname']?></td>	
					</tr>
					<tr>
						<td colspan=2 valign="top"><hr color="#e5e5e5"/></td>
					</tr>
					<tr>
						<td>商品编号:</td>
						<td><?=$one['pnums']?></td>
					</tr>
					<tr>
						<td>商品原价:</td>
						<td><strike><?=$one['price']?></strike></td>
					</tr>
					<tr>
						<td>特价优惠:</td>
						<td style="color:red;"><?php $price=$one['price']-$one['sprice'];echo $price2=number_format($price,2);?></td>
					</tr>
					<tr>
						<td>商品产地:</td>
						<td><?=$one['addr']?></td>
					</tr>
					<tr>
						<td>商品颜色:</td>
						<td>
						<?php $a=explode(',',$one['color']);for($i=0;$i<count($a);$i++){?>
							<div style="width:20px;height:20px;background:<?=$a[$i]?>;display:inline-block;"></div>
							<input type="radio" name="color" value="<?=$a[$i]?>" checked onclick="choose(this)"/>
						<?php }?>
						</td>
					</tr>
					<tr>
						<td>商品尺码:</td>
						<td>
						<?php $b=explode(',',$one['size']);for($i=0;$i<count($b);$i++){?>
						<input type="radio" name="size" value="<?=$b[$i]?>" checked><?=$b[$i]?>
						<?php }?>
						</td>
					</tr>
				
					<tr>
						<td>购买数量:</td>
						<td id="tt">
						<span id="jj" onclick="numm()">-</span>
						<input type="text" style="width:100px;height:30px;" name="num" value="1" id="num" oninput="numm()"/>
						<span id="add">+</span>库存<?=$one['snums']?>件
						</td>
						<script>
							function numm(){
								var a = document.getElementById("num");
								if (a.value<2)
								{
									a.value=1;
								}
								else if (a.value><?=$one['snums']?>)
								{
									a.value=<?=$one['snums']?>;
								}
							}
						</script>
					</tr>
				
					<tr>
						<td colspan=2>
						<input type="hidden" name="pid" value="<?=$one['pid']?>">
						<input type="hidden" name="type" value="1">
						<input type="hidden" name="price" value="<?=$price?>">

							<input type="submit" name="sub" value="立即购买" style="background-color:#6CBDEC; width:150px; height:40px ;color:white;font-size:23px;border-radius:10px;" formaction="order.php"/>
							<input type="submit" name="sub" value="加入购物车" style="background-color:#ffcc00; width:150px; height:40px ;color:white;font-size:23px;border-radius:10px;margin-left:100px;" />
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
		<div id="spms0" style="height:auto;">
			<div id="spms"><font style="font-size:1.1em;margin-left:70px;">商品描述:</font><hr/></div>
			<?=$one['descp']?>
		</div>
			<div id="yhpj">
				<font style="font-size:1.1em;margin-left:70px;">用户评论:</font><hr color="#eaeaea"/>
				<div>
					<?php $sql="select * from ts_message where goods_id=$pid";
					//echo $sql;
						$res=mysqli_query($link,$sql);
						//var_dump(mysqli_fetch_assoc($res));
						if(is_object($res))
						{
							if(mysqli_num_rows($res)>0)
							{
								$arr=array();
								while(($list=mysqli_fetch_assoc($res))!=false)
								{
									$arr[]=$list;
								}
							}
						}
						//print_r($arr);
					?>
					<table width="100%" height="50px;" border=0 cellspacing=0>
					<?php if(isset($arr)){foreach($arr as $v){echo $v['msg_content']; ?>
						<tr>
							<td><?=$v['msg_content']?></td>
							<td><font size="3"><?=date("Y-m-d",$v['msg_time'])?>&nbsp;<?php if($v['msg_star']==3){echo '好评';}elseif($v['msg_star']==2){echo '中评';}elseif($v['msg_star']==1){echo '差评';}?></font></td>
						</tr>
						<tr>
							<td colspan=2><hr/></td>
						</tr>
					<?php }}?>
					</table>
				</div>
			</div>

			<div id="pj0">
				
			</div>
		
			

		<div id="db">
			<div style="margin-left:800px;margin-top:10px;">
				关于我们|法律声明|工作机会|联系我们
			</div>

			<div style="margin-left:600px;margin-top:20px;color:#a8a8a8;">
				Copyright@2013 Thinksite Co.Let night reserved 经营许可证编号：苏A-12345678
			</div>
		</div>
		
	</div>
 </body>
<script type="text/javascript">
	function change(wmm)
	{
		one.src=wmm.src;
	}
	color=document.getElementsByName("color[]");
function choose(a)
{
	checkNum=0;
	for(let i=0;i<color.length;i++)
	{
		if(color[i].checked==true)
		{
			checkNum++;
		}
	}
	if(checkNum==0)
	{
		a.checked=true;
	}
}

jj=document.getElementById("jj");
jj.onclick=function()
{
	if(form.num.value>1)
	{
		form.num.value=form.num.value-1;
	}
}
add=document.getElementById("add");
add.onclick=function()
{
	if(form.num.value < <?=$one['snums']?>)
	{
		form.num.value=parseInt(form.num.value)+1;
	}
}
</script>
</html>